<?php
class IndexController extends HomeController{
	
	public $layout = "//layouts/base2";
	
	public function filters(){
		return array(
				array(
						'system.web.widgets.COutputCache + index',
						'duration'=>30
				)
		);
	}

	public function actionIndex(){
		
		//首页幻灯片数据
		$flash = $this->getFlashArticle();
		
		$picArticle = Article::model()->getPicArticle(array(10), array(47,48),2);
		
		
		
		$this->render('index', array(
				'flash'=>$flash,
				'picArticle'=>$picArticle
		));
	}
	
	//取得首页幻灯片的文章
	protected function getFlashArticle(){
		$sql = "SELECT a.title,a.pic,a.article_id 
				FROM {{article_attr}} aa
				LEFT JOIN {{article}} a
				ON aa.article_id = a.article_id
				WHERE aa.attr_id = 4
				LIMIT 0,5";
		$list = Yii::app()->db->createCommand($sql)->queryAll();
		return $list;
	}
	
	/**
	 * 错误页面
	 */
	public function actionError()
	{
		$this->layout = '';
		if($error=Yii::app()->errorHandler->error)
		{
			if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}

	public function actions(){
		return array(
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}
}